package com.openthinks.joyniproject.utils;

import java.io.File;
import java.io.FilenameFilter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 文件名过滤. 支持符号:*
 * @author Cloud
 *
 */
public class FileNameFilter implements FilenameFilter {

	/**
	 * 文件名规则
	 */
	private String fileNameRuler;
	
	public FileNameFilter(String fileNameRuler) {
		fileNameRuler = fileNameRuler.replace("*", ".*");
		this.fileNameRuler = fileNameRuler;
	}
	
	@Override
	public boolean accept(File dir, String name) {
		
		Pattern p = Pattern.compile(fileNameRuler); 
		Matcher m = p.matcher(name); 
		return m.matches();
	}
	
}
